package com.bwie.live.controller;
import com.bwie.common.utils.R;
import com.bwie.live.config.AliyunLiveConfig;
import com.bwie.live.config.AliyunLiveUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/aliyunLive")
@Slf4j
public class AliyunLiveController {

    @Resource
    private AliyunLiveConfig aliyunConfig;
    /**
     * 生成推流播流地址 //align推流以及拉流地址
     * sourceId  在这里我将它设置为房间号
     */
    @GetMapping("/save_Live")
    public R save_Live(HttpServletRequest request, @RequestParam("sourceId") String sourceId){
        try {
            //生成推流地址
            String pushUrl = AliyunLiveUtil.createPushUrl(sourceId, aliyunConfig);
            //生成播流地址
            String pullUrl = AliyunLiveUtil.createPullUrl(sourceId, aliyunConfig);
            return R.ok().put("push",pushUrl).put("pull",pullUrl);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.error();
    }
}